﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.ObjectModel
{
    using System.Diagnostics;

    /// <summary>
    /// Represents a method parameter.
    /// </summary>
    [DebuggerDisplay("Param {Name}: {ReturnType.Name}")]
    public class ParameterDefinition
    {
        private readonly static ParameterDefinition[] sEmptyParameters = {};
        private readonly bool mIsByRef;
        private readonly bool mIsParamArray;
        private readonly string mName;
        private readonly UnboundType mType;

        /// <summary>
        /// Initializes a new variant instance of the <see cref="ParameterDefinition"/> class.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        public ParameterDefinition(string name) : this(name, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterDefinition"/> class.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="type">The type of the parameter.</param>
        public ParameterDefinition(string name, UnboundType type) : this(name, type, true, false)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterDefinition"/> class.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="type">The type of the parameter.</param>
        /// <param name="isByRef">Whether the parameter is passed by reference or value.</param>
        /// <param name="isParamArray">Whether the parameter is a parameter array.</param>
        public ParameterDefinition(string name, UnboundType type, bool isByRef, bool isParamArray)
        {
            mName = name;
            mType = type ?? UnboundType.Variant;
            mIsByRef = isByRef;
            mIsParamArray = isParamArray;
        }

        /// <summary>
        /// Gets an empty array of parameter definitions.
        /// </summary>
        public static ParameterDefinition[] EmptyParameters
        {
            get { return sEmptyParameters; }
        }

        /// <summary>
        /// Gets the name of the parameter.
        /// </summary>
        public string Name
        {
            get { return mName; }
        }

        /// <summary>
        /// Determines whether the parameter is passed by reference.
        /// </summary>
        public bool IsByRef
        {
            get { return mIsByRef; }
        }

        /// <summary>
        /// Determines whether the parameter is a parameter array.
        /// </summary>
        public bool IsParamArray
        {
            get { return mIsParamArray; }
        }

        /// <summary>
        /// Gets the type of the parameter.
        /// </summary>
        public UnboundType Type
        {
            get { return mType; }
        }
    }
}
